package cz.data.domain.driver.kafka.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import cz.data.common.annotation.DataInner;
import cz.data.common.base.BaseResponse;
import cz.data.common.support.db.DbProperty;
import cz.data.common.support.db.core.DbColumn;
import cz.data.common.support.db.core.DbTable;
import cz.data.common.support.db.driver.TableOperation;
import cz.data.domain.driver.kafka.service.KafkaMetadataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = {"Kafka元数据API"})
@RestController
public class KafkaMetadataController {

    @Resource
    KafkaMetadataService service;

    @DataInner
    @ApiOperationSupport
    @ApiOperation(value = "Kafka-连接检验")
    @PostMapping("/api/driver/kafka/connect")
    public BaseResponse connect(@RequestBody DbProperty property) {
        return service.connect(property);
    }

    @DataInner
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "获取数据库表元数据")
    @GetMapping("/api/driver/kafka/tables")
    public List<DbTable> getSourceAllTable(String sourceId) {
        return service.getSourceAllTable(sourceId);
    }

    @DataInner
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取数据库表包含的列元数据")
    @GetMapping("/api/driver/kafka/columns")
    public List<DbColumn> getSourceTableColumns(String sourceId, String tableName) {
        return service.getSourceTableColumns(sourceId, tableName);
    }

    @DataInner
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "创建数据库表")
    @PostMapping("/api/driver/kafka/createTable")
    public Boolean createTable(@RequestBody TableOperation operation) {
        return service.createTable(operation);
    }

    @DataInner
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除数据库表")
    @PostMapping("/api/driver/kafka/dropTable")
    public Boolean dropTable(@RequestBody TableOperation operation) {
        return service.dropTable(operation);
    }
}
